package org.example.web;

import java.lang.reflect.Method;

public class WebHandler {
    private final Object helloController;
    private final Method method;
    private final ResultType resultType;

    public WebHandler(Object helloController, Method method){
        this.helloController = helloController;
        this.method = method;
        this.resultType = resolveResultType(method);
    }

    private ResultType resolveResultType(Method method) {
        if(method.isAnnotationPresent(ResponseBody.class)){
            return ResultType.JSON;
        }else if(method.getReturnType() == ModelAndView.class){
            return ResultType.LOCAL;
        }
        return ResultType.HTML;
    }

    public Object getHelloController() {
        return helloController;
    }

    public Method getMethod() {
        return method;
    }

    public ResultType getResultType() {
        return resultType;
    }

    enum ResultType{
        JSON, HTML, LOCAL
    }
}
